﻿using System.Collections.Generic;
using System.Device.Location;
using System.Linq;

namespace PushpinClusterer
{
    public class ClusteredPushpinItem<T> where T : IClusteredGeoObject
    {
        private readonly List<T> _geoObjects;

        public ClusteredPushpinItem()
        {
            _geoObjects = new List<T>();
        }

        public int ClusterCount
        {
            get
            {
                return _geoObjects.Count;
            }
        }

        public IEnumerable<T> ClusteredItems
        {
            get { return _geoObjects; }
        }

        public bool IsClustered
        {
            get
            {
                return _geoObjects.Count > 1;
            }
        }

        public GeoCoordinate Location
        {
            get
            {
                return _geoObjects.Any() ? _geoObjects.FirstOrDefault().Coordinate : null;
            }
        }

        public T CurrentObject
        {
            get
            {
                return _geoObjects.Any() ? _geoObjects.FirstOrDefault() : default(T); 
            }
        }

        public void Add(T locObject)
        {
            _geoObjects.Add(locObject);
        }

        public void AddRange(IEnumerable<T> locObject)
        {
            _geoObjects.AddRange(locObject);
        }
    }
}
